package com.special.threademo.concurrency.threadLocalRandom;

import java.io.InputStream;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.IntStream;

/**
 * Created with IDEA2020.3
 * author:LiuYC
 * DateTime:2021/1/22  13:15
 */
public class RandomDemo {
    public static void main(String[] args) {
        Random random = new Random();
        IntStream.range(1, 10).forEach(i -> {
            System.out.println(random.nextInt(10));
            /**
             * 问题，当多个线程增强到原始种子的时候，我们的后面的新种子就会出现性能问题。
             */
        });
        System.out.println("==================");
        ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
        IntStream.range(1, 10).forEach(i1 -> {
            System.out.println(threadLocalRandom.nextInt(10));
        });


        System.out.println(":===============");
    }
}
